package cts.business;

import java.util.List;
import java.util.Set;

import javassist.bytecode.Descriptor.Iterator;

import com.opensymphony.xwork2.ActionContext;

import cts.db.Exam;
import cts.db.User;
import cts.db.UserDAO;

public class UserOP {
	
	UserDAO userDAO = new UserDAO();
	
	public int login(String uname, String pwd){
		List<User> ulist = userDAO.findByUsername(uname);
		//查找不到该用户名
		if(ulist.size()==0)
			return -1;
		User user = ulist.get(0);
		if( user.getPwd().equals(pwd) ){
			return user.getUId();
		}else{
			return -1;
		}
	}
	
	public Set<Exam> getExams(){
		String uname = (String) ActionContext.getContext().getSession().get("uname");
		List<User> ulist = userDAO.findByUsername(uname);
		User user = ulist.get(0);
		Set<Exam> exams = user.getExams();
		return exams;
	}

}
